graphql-scalar
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.
TypeScript version (with breaking changes) of the following repos:
joonhocho/graphql-input-number
joonhocho/graphql-input-string
Get Started
npm install graphql-scalar
or
yarn add graphql-scalar
How to Use
import { createStringScalar, createIntScalar, createFloatScalar } from 'graphql-scalar';
const stringScalar = createStringScalar({
name: string;
description?: string;
capitalize?: 'characters' | 'words' | 'sentences' | 'first';
collapseWhitespace?: boolean;
lowercase?: boolean;
maxLength?: number;
minLength?: number;
nonEmpty?: boolean;
pattern?: RegExp | string;
singleline?: string;
trim?: boolean;
trimLeft?: boolean;
trimRight?: boolean;
truncate?: number;
uppercase?: boolean;
coerce?: ScalarCoerceFunction<TValue>;
errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
parse?: ScalarParseFunction<TValue, TInternal>;
sanitize?: ScalarSanitizeFunction<TValue>;
serialize?: ScalarSerializeFunction<TInternal, TExternal>;
validate?: ScalarValidateFunction<TValue>;
})
const intScalar = createIntScalar({
name: string;
description?: string;
maximum?: number;
minimum?: number;
coerce?: ScalarCoerceFunction<TValue>;
errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
parse?: ScalarParseFunction<TValue, TInternal>;
sanitize?: ScalarSanitizeFunction<TValue>;
serialize?: ScalarSerializeFunction<TInternal, TExternal>;
validate?: ScalarValidateFunction<TValue>;
})
License
MIT License